<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="900" destroy-on-close @closed="$emit('closed')">
		<el-card>
			<template #header>
				{{processItem.procedure_name}}
			</template>
			缸号：{{processItem.gh}}
		</el-card>
		<el-space wrap style="margin-top: 10px;">
			<div v-for="item in staffs" :key="item.id">
				<el-popconfirm title="确定分配吗？" @confirm="staffSalary(item)">
					<template #reference>
						<el-button  type="primary">{{item.name}}</el-button>
					</template>
				</el-popconfirm>
			</div>
		</el-space>

		<template #footer>
			<el-button @click="visible=false" >取 消</el-button>
			<el-button v-if="mode!='show'" type="primary" :loading="isSaveing" @click="submit()">保 存</el-button>
		</template>
	</el-dialog>


</template>

<script>
	import cloneDeep from 'lodash/cloneDeep'
	export default {
		emits: ['success', 'closed'],
		components: {
			
		},
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					show: '分配人员'
				},
				dialog: {
					sku: false
				},
				visible: false,
				isSaveing: false,
				//表单数据
				
				processItem: {}, 
				staffs: []
			}
		},
		mounted() {

		},
		methods: {
		
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this
			},
			
			async getStaffs() {
				var reqData = {
					process_name: this.processItem.process_name
				}

				var res = await this.$API.procedure.getStaffByProcess.get(reqData)

				this.staffs = res.data
			},

			async staffSalary(item) {
				var reqData = {
					task_id: this.processItem.id,
					staff_id: item.id
				}
				var res = await this.$API.procedure.setSalaryByPatch.post(reqData)

				this.processItem.staff_name = item.name
				this.processItem.staff_id = item.id
				
				if (res.code == 200) {
					this.$emit('success', this.processItem)
					this.visible = false
				} else {
					this.$message.error("操作失败"+ res.message)
				}
			},
			//表单注入数据
			setData(data){
				//可以和上面一样单个注入，也可以像下面一样直接合并进去
				this.processItem = cloneDeep(data)
				this.getStaffs()
			},
			
		}
	}
</script>

<style>
</style>
